/**
 * 
 */
package org.o14x.alpha.domain;

import org.eclipse.swt.dnd.FileTransfer;
import org.eclipse.ui.PlatformUI;

/**
 * Clipboard wrapper.
 * 
 * @author Olivier DANGREAUX
 */
public class Clipboard {
	/**
	 * The underlying eclipse clipboard.
	 */
	private org.eclipse.swt.dnd.Clipboard clipboard;

	/**
	 * Internal FileTransfer object.
	 */
	private FileTransfer fileTransfer;

	/**
	 * Last knowed status of the clipboard.
	 */
	private Boolean lastKnowedStatus;
	
	/**
	 * The content of the clipboard was setted within a cut operation.
	 */
	private boolean cut = false;

	/**
	 * Creates a new instance of Clipboard.
	 */
	public Clipboard() {
		clipboard = new org.eclipse.swt.dnd.Clipboard(PlatformUI.getWorkbench().getDisplay());
		fileTransfer = FileTransfer.getInstance();
	}

	/**
	 * Returns the value of lastKnowedStatus.
	 *
	 * @return The value of lastKnowedStatus.
	 */
	public Boolean getLastKnowedStatus() {
		return lastKnowedStatus;
	}

	/**
	 * Sets the value of lastKnowedStatus.
	 *
	 * @param lastKnowedStatus The value of lastKnowedStatus to set.
	 */
	public void setLastKnowedStatus(Boolean lastKnowedStatus) {
		this.lastKnowedStatus = lastKnowedStatus;
	}

	/**
	 * Returns the value of clipboard.
	 *
	 * @return The value of clipboard.
	 */
	public org.eclipse.swt.dnd.Clipboard getClipboard() {
		return clipboard;
	}

	/**
	 * Sets the value of clipboard.
	 *
	 * @param clipboard The value of clipboard to set.
	 */
	public void setClipboard(org.eclipse.swt.dnd.Clipboard clipboard) {
		this.clipboard = clipboard;
	}

	/**
	 * Indicates if the clipboard has some file content.
	 * 
	 * @return A boolean indicating if the clipboard has some file content;
	 */
	public boolean hasFileContent() {
		boolean hasFileContent = false;

		String[] selectedPaths = (String[]) clipboard.getContents(fileTransfer);
		hasFileContent = selectedPaths != null && selectedPaths.length != 0;

		return hasFileContent;
	}

	/**
	 * Return the status of the clipboard if it has changed from the last invocation of this method.
	 * 
	 * @return Boolean.TRUE if the clipbard contains some files, Boolean.FALSE if the clipbard does not contains some files, null if the status hasn't changed.
	 */
	public Boolean getStatusIfChanged() {
		Boolean status = null;
		Boolean currentStatus = new Boolean(hasFileContent());
		if (currentStatus != lastKnowedStatus) {
			status = currentStatus;
			lastKnowedStatus = currentStatus;
		}
		return status;
	}

	/**
	 * Returns the value of cut.
	 *
	 * @return The value of cut.
	 */
	public boolean isCut() {
		return cut;
	}

	/**
	 * Sets the value of cut.
	 *
	 * @param cut The value of cut to set.
	 */
	public void setCut(boolean cut) {
		this.cut = cut;
	}
}
